<div class="layui-container fly-marginTop">
  <div class="fly-panel fly-panel-user" pad20>
    <div class="layui-tab layui-tab-brief" lay-filter="user">
      <ul class="layui-tab-title">
        <li><a href="{:url('home/index/login')}">前往登录</a></li>
        <li class="layui-this">修改密码</li>
      </ul>
      <div class="layui-form layui-tab-content" id="LAY_ucm" style="padding: 20px 0;">
        <div class="layui-tab-item layui-show">
          <div class="layui-form layui-form-pane">
            <form method="post">

              <div class="layui-form-item">
                <label for="L_pass" class="layui-form-label">密码</label>
                <div class="layui-input-inline">
                  <input type="password" id="L_pass" name="password" required lay-verify="required" placeholder="请输入密码"
                    autocomplete="off" class="layui-input">
                </div>
              </div>

              <div class="layui-form-item">
                <label for="L_repass" class="layui-form-label">确认密码</label>
                <div class="layui-input-inline">
                  <input type="password" id="L_repass" name="repassword" required lay-verify="required"
                    placeholder="请输入确认密码" autocomplete="off" class="layui-input">
                </div>
              </div>

              <div class="layui-form-item">
                <label for="L_vercode" class="layui-form-label">验证码</label>
                <div class="layui-input-inline">
                  <input type="text" id="L_vercode" name="vercode" required lay-verify="required" placeholder="请输入验证码"
                    autocomplete="off" class="layui-input">
                </div>

                <div class="layui-form-mid" style="padding: 0 !important;display: block;">
                  <img src="{:url('home/index/captcha')}" alt="" class="imgCode">
                  <p onclick="changeCode()"
                    style="text-decoration: underline;color: blue;cursor: pointer;user-select: none;">
                    看不清，点击这里换一张</p>
                </div>
              </div>

              <div class="layui-form-item">
                <button class="layui-btn" type="button" id="auth">修改密码</button>
              </div>

            </form>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>
<script>
  // 点击切换验证码图片
  function changeCode() {
    document.querySelector(".imgCode").setAttribute('src', `{:url('home/index/captcha')}`)
  }

  layui.use('layer', function () {
    var layer = layui.layer
    var $ = layui.jquery

    // 验证邮箱操作
    // 验证邮箱操作
    $("#auth").on("click", function () {
      var password = $('#L_pass').val()
      var repassword = $('#L_repass').val()

      $.ajax({
        type: "POST",
        url: `{:url('home/index/repwd')}`,
        data: {
          password: password,
          repassword: repassword,
          email: `{$email}`
        },
        success: function (data) {
          layer.msg(data.msg);
          console.log(data);
          if (data.result) {
            setTimeout(() => {
              window.location.href = data.url;
            }, 3000)
          }
        }
      })

    })


  })

</script>